package demo3;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

class Person {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{name='" + name + "', age=" + age + "}";
    }
}

public class ListSortAndFilter {
    public static void main(String[] args) {
        List<Person> people = new ArrayList<>();
        people.add(new Person("Alice", 25));
        people.add(new Person("Bob", 18));
        people.add(new Person("Charlie", 22));
        List<Person> sortedAndFiltered = people.stream()
                .sorted(Comparator.comparingInt(p -> -p.age))
                .filter(p -> p.age > 20)
                .collect(Collectors.toList());
        System.out.println("按年龄从大到小排序并过滤出年龄大于 20 岁的人: " + sortedAndFiltered);
    }
}